package AnaliseSemantica;

import java.util.HashMap;
import java.util.Iterator;

/***/
public class Simbolo{
	
	/***/
	private static int id = 0;
	/***/
	private int value;
	/***/
	private static HashMap<String , Simbolo> dict = new HashMap<String, Simbolo>();
	
	/***/
	private Simbolo(int value){
		this.value = value;
	}
	
	/***/
	public static Simbolo symbol(String name){
		if(dict.containsKey(name)) return dict.get(name);
		else{
			Simbolo s = new Simbolo(getID());
			dict.put(name, s);
			return s;
		}
	}
	
	/***/
	private static int getID(){
		id++;
		return id - 1;
	}
	
	/***/
	public int compareTo(Object s){
		if(this.value == ((Simbolo)s).value) return 0;
		return 1;
	}
	
	/***/
	public boolean equals(Object s){
		return this.value == ((Simbolo)s).value;
	}
	
	/***/
	public String toString(){
		String name;
		Iterator<String> it = dict.keySet().iterator();
		while(it.hasNext()){
			name = it.next();
			if(dict.get(name).value == value) return name;
		}
		name = "Identificador nao valido";
		return name;
	}
	
}
